<?php

namespace IDock\Insurance\ZFIC\Request;

use IDock\Insurance\ZFIC\Response\CommonResponse;
use IDock\Insurance\ZFIC\Response\UploadFileResponse;
use IDock\Insurance\ZFIC\ZFICEnums;
use IDock\Visitor\UploadFileVisitor;

class UploadFileRequest extends AllZFICRequest
{

    protected $urlTip = '影像上传接口';
    protected $route = 'order/api/order/uploadFile';
    protected $inLog = true;

    protected $response = UploadFileResponse::class;

    /**
     * @var UploadFileVisitor $visitor
     */
    protected $visitor;

    public function generate(): array
    {
        $param = [
            "platOrderNo" => $this->visitor->argc['platOrderNo'],
            'imageInfoVMList' => $this->getImageList()
        ];
        return $param;
    }

    protected function getImageList()
    {
        $list = $this->visitor->getFileList();
        $isNewCar = $this->visitor->argc['isNewCar'] ? '01' : '02';
        $imageList = [];

        foreach ($list as $key => $val) {
            $file = file_get_contents($val['url']);
            $fileSize = ceil(strlen($file)/1000);
            $ext = basename($val['url']);
            $extArr = explode('.',$ext);
            $arr = [
                'fileName' => md5(mt_rand(10,10000)).mt_rand(1000,9999),
                'serialNo' => $key + 1,
                'fileType' => 'P',//图片
                'fileExt' => '.'.end($extArr),
                'typePath1' => '01',
                'typeName1' => '投保业务',
                'typePath2' => $this->visitor->argc['isNewCar'] ? '05' : '06',
                'typeName2' => $this->visitor->argc['isNewCar'] ? '新车' : '旧车',
                'typePath3' => ZFICEnums::$uploadImageType[$isNewCar][$val['type']] ?? '',
                'typeName3' => '',
                'fileSize' => $fileSize,
                'fileAddress' => '',
                'fileDate' => date('Y-m-d H:i:s'),
                'fileRemark' => '',
                'fileData' => base64_encode($file),
            ];
            $arr['typeName3'] = ZFICEnums::$uploadImageTypeName[$isNewCar][$arr['typePath3']] ?? '';
            $imageList[] = $arr;
        }
        return $imageList;

    }

    public function getStaffConfig(&$chalCode, &$userCode)
    {
        $chalCode = $this->visitor->argc['chalCode'] ?? '';
        $userCode = $this->visitor->argc['userCode'] ?? '';
    }


}